package org.jeecg.modules.workflow.dto;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.activiti.engine.query.Query;
import org.jeecg.common.api.vo.Result;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Create by Kalvin on 2020/4/20.
 */
public class ProcessQuery<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private T data;

    private Long count;

    public ProcessQuery() {

    }

    public ProcessQuery(T data) {
        this.data = data;
    }

    public ProcessQuery(T data, Long count) {
        this.data = data;
        this.count = count;
    }

    public ProcessQuery<T> listPage(Query query, int current, int size) {
        current--;
        this.count = query.count();
        this.data = (T) query.listPage(current * size, size);
        return this;
    }

    public Result toR() {
        Page page = new Page();
        page.setRecords((List)this.data);
        page.setTotal(this.count);
        return Result.ok(page);
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Long getCount() {
        return count;
    }

    public void setCount(Long count) {
        this.count = count;
    }
}
